package javaapplication3;
import java.util.*;
import java.io.*;


public class Main 
{
    public static long cr;
	public static boolean alog[];
    public static void main(String[] args)  throws IOException 
    {
        //genera();
        File outputFile = new File("casosDPBueno.out");
        File inputFile= new File("casosBueno.in");
        FileReader inf = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        BufferedWriter salida = new BufferedWriter(out);
        BufferedReader entr= new BufferedReader(inf);
        String h;
        h=entr.readLine();
        try
        {
            while (h!=null) //mientras no termine el archivo
            {
                int j= Integer.valueOf(h);
                Tupla moda;
                System.out.println("El prim leido: "+h.toString());
                h=entr.readLine();
                int indice;
                int[] arreglo=new int[j];
                int k=0;
                while (j-1>0)
                {
                    indice=h.indexOf(" ");
                    arreglo[k]=Integer.valueOf(h.substring(0, indice));
                    h=h.substring(indice+1, h.length());
                    j--;
                    k++;
                }
                arreglo[k]=Integer.valueOf((h.substring(0, h.length())).trim());
                h=entr.readLine();
                //calculo el tiempo inicial
                double tiempoInicio = System.currentTimeMillis();
                cr=0;
		alog=new boolean[arreglo.length];
                moda=obtieneModa2(arreglo, arreglo.length, 0, arreglo.length-1, 0);
                //calculo el tiempo final
                double tiempoFinal = System.currentTimeMillis();
                double tiempo = tiempoFinal - tiempoInicio;
                salida.write(String.valueOf(moda.getX()) + " Cant Elementos Arreglo: "+ String.valueOf(arreglo.length)+   " Cant Instrucciones: " + String.valueOf(cr));
                salida.newLine();
                salida.flush();
            }
        }
        finally
        {
            salida.close();
            entr.close();
        }
    }
    public static Tupla obtieneModa2(int[] a,int n, int desde, int hasta, int nivel)
    {
        if (n==1) 
        {
            Tupla res=new Tupla(a[desde], 1);
            return res;
        }
        else
        {
            Tupla m1=obtieneModa2(a, n/2, desde, desde+(n/2)-1, nivel+1);
            if (!alog[nivel])
            {
                cr++;
                alog[nivel]=true;
            }
            Tupla m2=obtieneModa2(a, n-(n/2), desde+(n/2), hasta, nivel+1);
            if (m1.getX()==m2.getX())
            {
                Tupla res=new Tupla(m1.getX(), m1.getY()+m2.getY());
                return res;
            }
            else
            {
                if (m1.getX()!=-1 && m2.getX()!=-1)
                {
                    if (m1.getY()>m2.getY())
                    {
                        Tupla res=new Tupla(m1.getX(), m1.getY()-m2.getY());
                        return res;
                    }
                    else
                    {
                        if (m1.getY()<m2.getY())
                        {
                            Tupla res=new Tupla(m2.getX(), m2.getY()-m1.getY());
                            return res;
                        }
                        else
                        {
                            Tupla res=new Tupla(-1, 0);
                            return res;
                        }
                    }
                    
                }
                else
                {
                    if (m1.getX()==-1 && m2.getX()==-1)
                    {
                            Tupla res=new Tupla(-1, 0);
                            return res;
                    }
                    else
                    {
                        if (m1.getX()==-1)
                        {
                            Tupla res=new Tupla(m2.getX(), m2.getY());
                            return res;
                        }
                        else 
                        {
                            Tupla res=new Tupla(m1.getX(), m1.getY());
                            return res;
                        }
                    }
                }
            }
                    
        }
    }
	public static int[] generaInstancias(int i)
	{
		int[] ret=new int[i];
		Random aleatorio = new Random();
		int moda = aleatorio.nextInt(100); 
		int j=i;
		int apariciones=0;
		int aparicionesModa=(i / 2)+1;
		while(j>0)
		{
			if (!((aparicionesModa-apariciones)==j))
			{
				if (aleatorio.nextInt(100)%2==0)
				{
					ret[j-1]=moda;
					apariciones++;
				}
				else
				{
					ret[j-1]=aleatorio.nextInt(100);
				}
			}
			else
			{
				ret[j-1]=moda;
				apariciones++;
			}
			j--;
		}
         return ret;
	}
public static void genera() throws IOException
{
        File casosG = new File("casosBueno.in");
        FileWriter sal = new FileWriter(casosG);
        BufferedWriter salid = new BufferedWriter(sal);
        try
        {
            int casoNro=0;
            int incremento=10;
            int ij=1;
            int multi=1;
            while (casoNro<50000000)
            {
                casoNro=casoNro+(incremento*multi);
                int[] arreglin= generaInstancias(casoNro);
                int t=0;
                salid.write(String.valueOf(arreglin.length));
                salid.newLine();
                while (t<arreglin.length)
                {
                    if (t==arreglin.length)
                    {
                        salid.write(String.valueOf(arreglin[t]));
                        t++;
                    }
                    else
                    {
                        salid.write(String.valueOf(arreglin[t]) + " ");
                        t++;
                    }
                }
                salid.newLine();
                salid.flush();
                ij++;
                if (ij==10)
                {
                    multi=multi*10;
                    ij=1;
                    casoNro=0;
                }
            }
        }
        finally
        {
            salid.close();
        }
}
    
}



/*
package javaapplication3;
import java.util.*;
/**
 *
 
 
public class Main {

    public static void main(String[] args) {
        int[] arr = new int[10];
       /* int i=0;
       while (i<10)
        {
            arr[i]=i+1;
            i++;
        }
        arr[0]=5;
        arr[1]=5;
        arr[2]=5;
        arr[3]=5;
        arr[4]=1;
        arr[5]=1;
        arr[6]=1;
        arr[7]=1;
        arr[8]=1;
        arr[9]=1;
        HashSet hs=new HashSet();
        permuto(arr, 0, 9, "", true, hs);
        System.out.print(" ++++++++++++++++++++++++++++++++ ");
        System.out.println(hs);
    }
    public static void permuto(int[] arr, int dsd, int hst, String c, boolean b, HashSet hs)
    {
        int i=0;
        int aux;
        while (i<hst-dsd+1)
        {
            if ((hst-dsd)==1)
            {
                int tmp;
                System.out.println(c+ " " + String.valueOf(arr[dsd])+" "+String.valueOf(arr[hst]));
                hs.add(c+ " " + String.valueOf(arr[dsd])+" "+String.valueOf(arr[hst]));
                tmp=arr[hst];
                arr[hst]=arr[dsd];
                arr[dsd]=tmp;
                i++;
            }
            else
            {
                int[] ref = new int[hst-dsd];
                int j=0;
                while (j<hst-dsd)
                {
                    ref[j]=arr[dsd+j+1];
                    j++;
                }
                permuto(ref, 0, hst-1, c + " " + String.valueOf(arr[dsd]), false, hs);
                i++;
                if (i<hst+1)
                {
                    aux=arr[dsd];
                    arr[dsd]=arr[i];
                    arr[i]=aux;
                }
                if (b==true)
                {
                    c="";
                }
            }
        }
    }
}
*/